<template>
  <div class="container">
    <!-- 顶部导航栏 -->
    <mt-header fixed title="小张购物商城">
      <span slot="left" @click="back" v-show="tolshow">
        <mt-button icon="back"></mt-button>
      </span>
    </mt-header>

    <!-- 路由显示模块 -->
    <transition>
      <router-view />
    </transition>

    <!-- 底部导航栏 -->
    <nav class="mui-bar mui-bar-tab">
      <router-link class="mui-tab-item-zl" to="/home">
        <span class="mui-icon iconfont">&#xe6a9;</span>
        <span class="mui-tab-label">首页</span>
      </router-link>
      <router-link class="mui-tab-item-zl" to="/member">
        <span class="mui-icon iconfont">&#xe63a;</span>
        <span class="mui-tab-label">会员</span>
      </router-link>
      <router-link class="mui-tab-item-zl" to="/shop">
        <span class="mui-icon iconfont">
          &#xe628;
          <span class="mui-badge" id="spanid">{{ this.$store.getters.getAllcount}}</span>
        </span>
        <span class="mui-tab-label">购物车</span>
      </router-link>
      <router-link class="mui-tab-item-zl" to="/search">
        <span class="mui-icon iconfont">&#xe68d;</span>
        <span class="mui-tab-label">搜索</span>
      </router-link>
    </nav>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      tolshow: false,//返回按钮显示状态
    };
  },
  created() {
    // 解决当前刷新会使tolshow为false
    // 如果当前路径为/home则tolshow为false否则为true
    this.tolshow=this.$route.path==='/home'? false : true
  },
  methods: {
    back() {
      this.$router.go(-1);
    }
  },
  watch: {
    '$route.path': function(newVal) {
      if (newVal === "/home") {
        this.tolshow = false;
      } else {
        this.tolshow = true;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding-top: 0.8rem;
  overflow: hidden;
  background-color: #fff;
  .mint-header {
    z-index: 99;
  }
  .v-enter {
    opacity: 0;
    transform: translateX(100%);
  }
  .v-leave-to {
    opacity: 0;
    position: absolute;
    transform: translateX(-100%);
  }
  .v-enter-active,
  .v-leave-active {
    transition: all 0.2s ease-in-out;
  }
  // 该类名，解决 tabbar 点击无法切换的问题
  .mui-bar-tab .mui-tab-item-zl.mui-active {
    color: #007aff;
  }

  .mui-bar-tab .mui-tab-item-zl {
    display: table-cell;
    overflow: hidden;
    width: 1%;
    height: 50px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #929292;
  }

  .mui-bar-tab .mui-tab-item-zl .mui-icon {
    top: 3px;
    width: 24px;
    height: 24px;
    padding-top: 0;
    padding-bottom: 0;
  }

  .mui-bar-tab .mui-tab-item-zl .mui-icon ~ .mui-tab-label {
    font-size: 11px;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
</style>
